package com.share.mongo.repository


import spock.lang.Specification
import spock.lang.Timeout

import java.util.concurrent.TimeUnit
/**
 * @author caifan* @created 2021/3/29
 * description: 
 */
@Timeout(value = 10, unit = TimeUnit.SECONDS)
class DemoTest extends Specification {

    def "add"() {
        expect:
        1 + 1 == 2
    }

    def "update"() {
        given: def name = "张三"
        println(name + "hello")
    }

    def "HashMap null Key"() {
        given:
        def map = new HashMap()

        when:
        map.put(null, "elem")

        then:
        notThrown(NullPointerException)
    }

    def "whenAndThen"() {
        given:
        def stack = new Stack()
        def elem = "push me"

        when:
        stack.push(elem)

        then:
        !stack.empty
        stack.size() == 1
        stack.peek() == elem
    }

    def "whenAndThenException"() {
        given:
        def stack = new Stack()
        assert stack.empty

        when:
        stack.pop()

        then:
        thrown(EmptyStackException)
        stack.empty
    }

    def "whenAndThenInteractions"() {

    }

    def "cleanTest"() {
        given: "创建文件"
        def file = new File("D:/ab.txt")
        file.createNewFile()

        and: "写入内容"
        file.write("hello")


        cleanup: "删除文件释放资源"
        file.delete()
    }

    def "computing the maximum of two numbers"() {
        expect:
        Math.max(a, b) == c

        where:
        a << [5, 3, 4]
        b << [1, 9, 8]
        c << [5, 9, 8]
    }
}
